<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>修改用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/layuiadmin/layui/css/layui.css" media="all">
    <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
    <script src="../../static/layuiadmin/layui/layui.js"></script>
    <script src="../../static/jslib/jquery.validate.js" src="@{/jslib/jquery.validate.js}"></script>

    <script>
        layui.use(['form'],function (){
            var form = layui.form
                ,disable = false
                , layer = layui.layer

            $("#email").blur(function () {
                var email = $("#email").val();
                var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
                if (!reg.test(email)) {
                    layer.msg('邮箱不合法！！！', {icon: 5, time: 1000});
                }
            });

            $("#mobile").blur(function () {
                var mobile = $("#mobile").val();
                var reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
                if (!reg.test(mobile)) {
                    layer.msg('手机号码不合法！！！', {icon: 5, time: 1000});
                }
            });

            //监听提交(修改部门)
            form.on('submit(update)', function (data) {
                var mobile = data.field.mobile
                    , email = data.field.email

                var reg2 = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
                if (!reg2.test(email)) {
                    layer.msg('请输入有效的邮箱！', {icon: 2});
                    return false;
                }

                var reg3 = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
                if (!reg3.test(mobile)) {
                    layer.msg('请输入有效的手机号码！', {icon: 2});
                    return false;
                }
                event.preventDefault();
                if (disable) return
                disable = true
                $.ajax({
                    type: "POST",
                    url: "/ams-admin/admin/update",
                    data: JSON.stringify(data.field),
                    contentType: "application/json",
                    success: function (r) {
                         disable = false
                        if(r.code === 0){
                            layer.msg("修改成功！",{icon: 2, time: 1000})
                            window.parent.location.reload()
                            parent.layer.close(index)
                        }else {
                            layer.msg(r.message,{icon: 5,time:1000});
                        }
                    }
                });
            })
        });
    </script>
    <style>
        .error {
            color: red;
        }
    </style>
</head>
<body>


<form class="layui-form" id="frm1" lay-filter="example">
    <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">用户名<i style="color: red">*</i></label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                    <span errors="*{username}" class="error"></span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">用户部门<i style="color: red">*</i></label>
                <div class="layui-input-inline">
                    <select name="deptId" lay-reqtext="请选择部门" id="deptId" lay-search="">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <input type="hidden" id="user_id" name="userId"  autocomplete="off" class="layui-input" width="100">
            <input type="text" style="display: none" id="userAccount" name="useraccount"  placeholder="请输入用户的账号" autocomplete="off" class="layui-input">
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">手机号码<i style="color: red">*</i></label>
                <div class="layui-input-inline">
                    <input type="text" id="mobile" name="mobile" lay-verify="phone" placeholder="请输入号码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">邮箱<i style="color: red">*</i></label>
                <div class="layui-input-inline">
                    <input type="email" id="email" name="email" lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">地址<i style="color: red">*</i></label>
                <div class="layui-input-inline">
                    <input type="text" id="address" name="address"  placeholder="请输入用户地址" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">状态<i style="color: red">*</i></label>
                <div class="layui-input-inline">
                    <select name="status" lay-reqtext="请选择状态！" id="status" lay-search="">
                        <option value="请选择状态">请选择状态</option>
                        <option value="Y">启用</option>
                        <option value="N">禁用</option>
                    </select>
                </div>
            </div>
        </div>

    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-block">
                <input type="submit" class="layui-btn" lay-submit="" lay-filter="update" value="确认修改">
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>

</form>
</body>
</html>